package com.example.compete.mapper;

import com.example.compete.DTO.EducationTypeDTO;
import com.example.compete.DTO.ExecutiveDTO;
import com.example.compete.DTO.PostTypeDTO;
import com.example.compete.DTO.SexTypeDTO;

import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExecutiveMapper {
	//查找所有高管信息
    @Select("select * from company_executive_information")
    List<ExecutiveDTO> findAll();
    
    //查找所有学历信息
    @Select("select * from education_details")
    List<EducationTypeDTO> findAllEducationType();

    //查找所有职务信息
    @Select("select * from post_details") 
    List<PostTypeDTO> findAllPostType();
    
    //查找所有性别信息
    @Select("select * from sex_details")
    List<SexTypeDTO> findAllSexType();
    
    //根据高管编号查看高管信息
    @Select("select * from company_executive_information where EXECUTIVE_ID = #{executiveId}")
    ExecutiveDTO findByExecutiveId(String executiveId);

    //添加高管信息
    @Insert("insert into company_executive_information(EXECUTIVE_ID,COMPANY_ID,EXECUTIVE_NAME,POST,SEX,BIRTHDAY,EDUCATION,REGISTERED_TIME,UPDATE_TIME) " +
            "values(#{executiveId},#{companyId},#{executiveName},#{post},#{sex},#{birthday},#{education},#{registeredTime},#{updateTime})")
    void add(ExecutiveDTO executiveDTO);

    //根据高管编号修改高管信息
    @Update("update company_executive_information set COMPANY_ID = #{companyId}, EXECUTIVE_NAME = #{executiveName}, POST = #{post}," +
            "SEX = #{sex}, BIRTHDAY = #{birthday}, EDUCATION = #{education}, REGISTERED_TIME = #{registeredTime}, UPDATE_TIME = #{updateTime} where EXECUTIVE_ID = #{executiveId}")
    void updateExecutive(ExecutiveDTO executiveDTO);

    //根据高管编号删除高管信息
    @Delete("delete from company_executive_information where EXECUTIVE_ID = #{executiveId}")
    int deleteByExecutiveId(String executiveId);
    
    //根据公司编号查看高管信息
    @Select("select * from company_executive_information where COMPANY_ID = #{companyId}")
    List<ExecutiveDTO> selectAllByCompanyId(String companyId);
    
    //根据职务编号查找职务名称
    @Select("select POST_TYPE from post_details where POST_ID = #{postId}")
    String findPostName(int postId);

    //查找性别名称
    @Select("select SEX_TYPE from sex_details where SEX_ID = #{sexId}")
    String findSexName(int sexId);

    //查找学历名称
    @Select("select EDUCATION_TYPE from education_details where EDUCATION_ID = #{educationId}")
    String findEducationName(int educationId);
}
